package com.turman.blibrary.log;

/**
* 堆栈打印器
* @author buobao
* @since 2024/2/27 9:50
*/
public class BStackTraceFormatter implements BLogFormatter<StackTraceElement[]> {
    @Override
    public String format(StackTraceElement[] data) {
        StringBuilder sb = new StringBuilder(128);
        if (data==null || data.length == 0) {
            return null;
        } else if (data.length == 1) {
            return "\t- "+data[0].toString();
        } else {
            for (int i = 0,len=data.length; i < len; i++) {
                if (i==data.length-1) {
                    sb.append("\t└");
                    sb.append(data[i]).toString();
                } else {
                    if (i==0) {
                        sb.append("stackTrace:\n");
                    }
                    sb.append("\t├");
                    sb.append(data[i].toString());
                    sb.append("\n");
                }
            }
            return sb.toString();
        }
    }
}
